/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef DET_H
#define DET_H

#include "Std_Types.h"

#ifdef __cplusplus
extern "C" {
#endif
/* Version and Check Begin */
/* Version Info Begin */
#define DET_H_VENDOR_ID    0x8C
#define DET_H_AR_RELEASE_MAJOR_VERSION    4
#define DET_H_AR_RELEASE_MINOR_VERSION    3
#define DET_H_AR_RELEASE_REVISION_VERSION 1
#define DET_H_SW_MAJOR_VERSION    1
#define DET_H_SW_MINOR_VERSION    0
#define DET_H_SW_PATCH_VERSION    0
/* Version Info End */
/* Version and Check End */

#define DET_MODULE_ID 15


extern VAR(uint16, DET_VAR) Det_ModuleId;       /**< @brief DET module ID*/
extern VAR(uint8, DET_VAR) Det_InstanceId;      /**< @brief DET instance ID*/
extern VAR(uint8, DET_VAR) Det_ApiId;           /**< @brief DET API ID*/
extern VAR(uint8, DET_VAR) Det_ErrorId;         /**< @brief DET Error ID*/

typedef uint32 Det_ConfigType;

/* [SWS_Det_00019] The DET shall provide the initialization function Det_Init */
/**
 * @brief   Service to initialize the Default Error Tracer.
 * @details Service ID: 0x00, Synchronous, Non Reentrant.
 */
FUNC(void, DET_CODE) Det_Init(const Det_ConfigType *ConfigPtr);

/**
 * @brief   Service to report development errors.
 * @detials Service ID 0x01, Never return, Reentrant.
 * @param   ModuleId Module ID of calling module
 * @param   InstanceId  The identifier of the index based instance of a module, starting from 0,
 *          If the module is a single instance module it shall pass 0 as the InstanceId.
 * @param   ApiId ID of API service in which error is detected (defined in SWS of calling module)
 * @param   ErrorId ID of detected development error (defined in SWS of calling module).
 * @return  never returns a value, but has a return type for compatibility with services and hooks.
 */
FUNC(Std_ReturnType, DET_CODE) Det_ReportError(
    VAR(uint16, AUTOMATIC) ModuleId,
    VAR(uint8, AUTOMATIC) InstanceId,
    VAR(uint8, AUTOMATIC) ApiId,
    VAR(uint8, AUTOMATIC) ErrorId
);

/**
 * @brief   Service to report runtime errors.
 *
 * @detials If a callout has been configured then this callout shall be called.
            Service ID 0x04, Synchronous, Reentrant.
 *
 * @param   ModuleId Module ID of calling module
 * @param   InstanceId  The identifier of the index based instance of a module, starting from 0,
 *          If the module is a single instance module it shall pass 0 as the InstanceId.
 * @param   ApiId ID of API service in which error is detected (defined in SWS of calling module)
 * @param   ErrorId ID of detected development error (defined in SWS of calling module).
 *
 * @return  Returns always E_OK (is required for services)
 */
FUNC(Std_ReturnType, DET_CODE) Det_ReportRuntimeError(
    VAR(uint16, AUTOMATIC) ModuleId,
    VAR(uint8, AUTOMATIC) InstanceId,
    VAR(uint8, AUTOMATIC) ApiId,
    VAR(uint8, AUTOMATIC) ErrorId
);

/**
 * @brief   Service to report transient faults.
 *
 * @detials If a callout has been configured then this callout shall be called, If a callout has
 *          been configured than this callout shall be called and the returned value of the callout
 *          shall be returned. Otherwise it returns immediately with E_OK.
 *          Service ID 0x04, Synchronous, Reentrant.
 *
 * @param   ModuleId Module ID of calling module
 * @param   InstanceId  The identifier of the index based instance of a module, starting from 0,
 *          If the module is a single instance module it shall pass 0 as the InstanceId.
 * @param   ApiId ID of API service in which error is detected (defined in SWS of calling module)
 * @param   ErrorId ID of detected development error (defined in SWS of calling module).
 *
 * @return  the returned value of the callout if callout exist, otherwise E_OK.
 */
FUNC(Std_ReturnType, DET_CODE) Det_ReportTransientFault(
    VAR(uint16, AUTOMATIC) ModuleId,
    VAR(uint8, AUTOMATIC) InstanceId,
    VAR(uint8, AUTOMATIC) ApiId,
    VAR(uint8, AUTOMATIC) ErrorId
);

/**
 * @brief   Returns the version information of this module.
 *
 * @details SeviceID: 0x03, Synchronous, Reentrant.

 * @param   versioninfo     Pointer to where to store the version information of this module. If
 *                          In case a null pointer is passed, DET_E_PARAM_POINTER is returned.
 */
FUNC(void, DET_CODE) Det_GetVersionInfo(
    P2VAR(Std_VersionInfoType, AUTOMATIC, DET_APPL_DATA) versioninfo
);

/**
 * @brief   Service to start the Default Error Tracer.
 */
FUNC(void, DET_CODE) Det_Start(void);


FUNC(sint32, DET_CODE) Det_Validate(
    VAR(uint16, AUTOMATIC) ModuleId,
    VAR(uint8, AUTOMATIC) InstanceId,
    VAR(uint8, AUTOMATIC) ApiId,
    VAR(uint8, AUTOMATIC) ErrorId
);
FUNC(void, DET_CODE) Det_Clean(void);
#ifdef __cplusplus
}
#endif

#endif /* #ifndef DET_H */
